package com.guigu.auth.controller;


import com.guigu.auth.entity.dto.AuthMenuDTO;
import com.guigu.auth.entity.vo.AuthMenuRouterVO;
import com.guigu.auth.entity.vo.AuthMenuVO;
import com.guigu.auth.service.AuthMenuService;
import com.guigu.tms.result.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Set;

/**
 * <p>
 * 菜单 前端控制器
 * </p>
 *
 * @author TaoLong
 * @since 2021-12-06
 */
@RestController
@RequestMapping("/auth/auth-menu")
@Api(tags = "菜单管理")
@CacheConfig(cacheNames = "authMenu")
public class AuthMenuController {

    @Autowired
    private AuthMenuService authMenuService;

    /**
     * 查询所有权限
     *
     * @return
     */
    @GetMapping("/findAllAuthMenu")
    @ApiOperation("查询所有菜单")
    public R<List<AuthMenuVO>> findAllAuthMenu() {
        R<List<AuthMenuVO>> r = authMenuService.queryAllMenu();
        return r;
    }

    @GetMapping("queryAllMenuRouter")
    @ApiOperation("查询所有路由表菜单信息")
    public R<List<AuthMenuRouterVO>> queryAllMenuRouter(HttpServletRequest request) {
        return authMenuService.queryAllMenuRouter(request);
    }

    @PostMapping("/")
    @ApiOperation("添加菜单")
    @CacheEvict(allEntries = true)
    public R addMenu(@RequestBody AuthMenuDTO authMenuDTO) {
        return authMenuService.addAuthMenu(authMenuDTO);
    }

    /**
     * 根据岗位Id查询该岗位对应的菜单信息
     *
     * @param stationId
     * @return
     */
    @ApiOperation("根据岗位Id查询该岗位对应的菜单信息")
    @GetMapping("/queryMenuBasedOnStationId/{stationId}")
    @ApiImplicitParam(name = "stationId", value = "岗位Id")
    public R<Set<Long>> queryMenuBasedOnStationId(@PathVariable String stationId) {
        R<Set<Long>> r = authMenuService.queryMenuBasedOnStationId(stationId);
        return r;
    }


    /**
     * 根据角色Id查询对应的菜单信息
     *
     * @param roleId 角色id
     * @return
     */
    @GetMapping("/queryMenuBaseOnRoleId/{roleId}")
    @ApiOperation("根据角色Id查询对应的菜单信息")
    @ApiImplicitParam(name = "roleId", value = "角色ID")
    public R<List<Long>> queryMenuBaseOnRoleId(@PathVariable String roleId) {
        R<List<Long>> r = authMenuService.queryMenuBaseOnRoleId(roleId);
        return r;
    }
}

